package com.github.io.controller;

import com.github.io.annotation.Api;
import com.github.io.annotation.ApiOperateNote;
import com.github.io.websocket.MyWebSocketHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.socket.TextMessage;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2022/8/24 12:20
 * Description: 测试 WebSocket 推送功能，模拟数据源
 */

@RestController
@Api(value = "消息推送控制器")
@RequestMapping("/ws")
public class WSController {

    
    @ApiOperateNote(value = "推送消息", note = "推送消息")
    @GetMapping
    public String pushData(@RequestParam(defaultValue = "test data") String message) {
        MyWebSocketHandler.sendMessageToUser(new TextMessage(message));
        return "success";
    }
}
